import { Game } from './game/game';
import { CanvasController } from './ui/controllers/canvas.controller';

export class App {
  run() {
    const canvasController = new CanvasController();

    canvasController.onCanvasReady.listen((canvasElement) => {
      const game = new Game(canvasElement!);

      game.onLoading.listen((isLoading) => {
        canvasController.changeLoading(isLoading!);
      });

      game.onGameOver.listen((isVictorious) => {
        canvasController.finish(isVictorious!);
        game.finish();
      });

      game.start();
    });

    canvasController.start();
  }
}
